/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 * */

// AmzServer - Tototoy's server model.
// Author: tonyjobmails@gmail.com (tonyhack).
//
// Define class MessagePacket.
//
// MessagePacket uses to packet/unpacket message.
//

#ifndef __PACKET__INTERFACE__H
#define __PACKET__INTERFACE__H

#include "compress_interface.h"
#include "encrypt_interface.h"
#include "byte_buffer_dynamic.h"

namespace amz {

class MessagePacket {
 public:
  MessagePacket(CompressType compress, EncryptType encrypt);
  virtual ~MessagePacket();

  // Calculate size.
  inline int CalculatePacketSize(int size) {
    return this->compress_interface_->CalculateCompressSize(
           this->encrypt_interface_->CalculateEncryptSize(size));
  }
  inline int CalculateUnpacketSize(int size) {
    return this->encrypt_interface_->CalculateUnencryptSize(
           this->compress_interface_->CalculateUncompressSize(size));
  }

  // Packet/Unpacket
  // return the length.
  // read PacketErrorType.
  int Packet(const char *in, int size, char *out, int max_size);
  int Unpacket(const char *in, int size, char *out, int max_size);

 private:
  CompressInterface *compress_interface_;
  EncryptInterface *encrypt_interface_;

  SimpleByteBufferDynamic buffer_;
};

}  // namespace amz

#endif  // __PACKET__INTERFACE__H
